package ru.amse.tsyganov.jumleditor.commands;

import ru.amse.tsyganov.jumleditor.model.common.Edge;
import ru.amse.tsyganov.jumleditor.view.common.EdgeView;

/*package*/ class NewEdgeCommand extends Command {
	
	private final EdgeView<? extends Edge> edgeView;
	
	public NewEdgeCommand(
			EdgeView<? extends Edge> edgeView) {
		
		if (edgeView == null) {
			throw new IllegalArgumentException();
		}
		
		this.edgeView = edgeView;
	}
	
	@Override
	public void execute() {
		edgeView.getModelViewMap().getEdgesMap().
			put(edgeView.getModel(), edgeView);
		
		edgeView.getModel().addBindings();
	}

	@Override
	public void unexecute() {
		edgeView.getModelViewMap().getEdgesMap().
			remove(edgeView.getModel());
		
		edgeView.getSelectedItems().
			selectedTransitionsRemove(edgeView);
				
		edgeView.getModel().removeBindings();
		edgeView.getActivityGraphView().
			getSelectedItems().getSelectedTransitions().
				remove(edgeView);
	}
}
